"""
@name : 10-29homework
@author : hj
@projectname: CJH
"""

import string

## 1、给定一个整数，然后将它转为千分位格式化
str1 = '12346679461131'
# 反转
str2 = str1[::-1]
str3 = ''
# 循环遍历,加分隔符
for i in range(len(str2)):
    if i % 3 == 0 and i != 0:
        str3 = str3 + ","
    str3 = str3 + str2[i]
# 再反转
str4 = str3[::-1]
print(str4)

## 2、实现九九乘法表输出
for i in range(1, 10):  # 第二个乘数 行
    for j in range(1, i + 1):  # 第一个乘数  列
        print('{}x{}={}'.format(j, i, j * i), end=' ')
    print()  # 换行

## 3、猜金币游戏
import random

money = 1000
num = 0
win_num = 0
while money >= 100:
    guess = input("猜大还是猜小？ ")
    a = random.randint(1, 6)
    b = random.randint(1, 6)
    c = random.randint(1, 6)
    if guess == "exit":
        rate = win_num / num
        print(f"退出，玩了{num}次，赢了{win_num}次，胜率为{rate}")
        break
    elif (3 <= a + b + c <= 10 and guess == '小') or (11 <= a + b + c <= 18 and guess == '大'):
        money += 100
        print("猜对了，金币+100，剩余金币为：", money)
        win_num += 1
        num += 1
    elif (3 <= a + b + c <= 10 and guess == '大') or (11 <= a + b + c <= 18 and guess == '小'):
        money -= 100
        num += 1
        print("猜错了，金币-100，剩余金币为：", money)
    else:
        print("请输入'大'或'小'或exit，否则无法执行")

